<!-- 预约的列表表单 -->
<template>
  <div class="contain">
    <div class="form-wrap">
      <div class="form-choice line">
        <datetime class="vux-form-require" 
                  format="YYYY-MM-DD HH:mm"
                  v-model="arriveTime" 
                  :show.sync="visibility" 
                  title="提货时间" 
                  :start-date="today"
                  placeholder="点击选择"></datetime>
      </div>
      <div class="form-choice line">
        <x-address class="vux-form-require" title="提货省市区" v-model="addrvalue" :list="addressData" value-text-align="left" placeholder="点击选择">
        </x-address>
      </div>
      <div class="form-wrap-row">
        <div class="line displayflex">
          <div class="label"><span class="red">*</span>提货地址</div>
          <div class="ipt flex1">
            <textarea class="form-txtarea" type="text" placeholder="请输入详细的街道地址" v-model="address"></textarea>
          </div>
        </div>
      </div>
     
    </div>
    <div class="form-btn" @click="sure()">确定</div>
  </div>
</template>

<script>
export default {
  name: "choiceForm",
  data() {
    return {
      addrvalue: [],
      addressData: this.ChinaAddressV3Data,
      arriveTime: "",
      visibility: false,
      address: "",
      today: "",
      address: "",
    };
  },
  created() {
    this.type = this.$route.query.type;
    this.getToday();
    this.getAddress();
  },
  methods: {
    getToday() {
      var date = new Date(),
        year = date.getFullYear(),
        month = date.getMonth() + 1,
        day = date.getDate();
      if (month < 9) {
        month = "0" + month;
      }
      if (day < 9) {
        day = "0" + day;
      }
      var time = year + "-" + month + "-" + day;
      this.today = time;
    },
    getAddress() {
      var self = this;
      var userinfo = JSON.parse(localStorage.userinfo);
      var query = {
        CCGUID: userinfo.StaffID,
        IsChecked: "Y"
      };
      this.Ajax.post("SearchCustomerAddressApi", query).then(function(resp) {
        console.log(resp.Datas);
        self.addrvalue.push(resp.Datas[0].Province);
        self.addrvalue.push(resp.Datas[0].City);
        self.addrvalue.push(resp.Datas[0].District);
        self.address = resp.Datas[0].Address;
      });
    },
    sure() {
      if (this.addrvalue.length == 0) {
        this.Toast({
          message: "请填写提货省市区"
        });
        return false;
      }
      if (!this.address) {
        this.Toast({
          message: "请填写提货地址"
        });
        return false;
      }
      if (!this.arriveTime) {
        this.Toast({
          message: "请填写提货时间"
        });
        return false;
      }
      var self = this;
      var userinfo = JSON.parse(localStorage.userinfo);
      var query = {
        medpo: JSON.parse(sessionStorage.items),
        bespeak: JSON.parse(sessionStorage.selectuseritems),
        CreateUserName: userinfo.Name,
        CreateUserId: userinfo.StaffID,
        BespeakType: this.type,
        Province: this.addrvalue[0],
        City: this.addrvalue[1],
        District: this.addrvalue[2],
        Address: this.address,
        thtime: this.arriveTime
      };
      this.Ajax.post("CreateTRmedpobespeak", query).then(function(resp) {
        if (resp.IsSuccess) {
          self.Ajax.post("BespeakGoPush", query).then(function(resp){}); // 执行推送
          self.MessageBox.alert("预约成功").then(action => {
            sessionStorage.clear();
            self.$router.push({
              path: "/order/appointList",
              query: { type: self.type }
            });
          });
        } else {
          self.Toast({
            message: resp.ErrorMessage || "操作失败，请稍后重试"
          });
        }
      });
    }
  }
};
</script>